package be.wavenet.web;

import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class HelloServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private String formattedDate;
	private String formattedTime;
       
   
    public HelloServlet() {
        super();
    
    }
 
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		PrintWriter out = response.getWriter();
		
		SimpleDateFormat dateFormat = new SimpleDateFormat("EEEEE dd MMMMM yyyy");
		SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm");
		Date now = new Date();
		
		formattedDate = dateFormat.format(now);
		formattedTime= timeFormat.format(now);
		
		String username = request.getParameter("username");
		if (username == null || username.isEmpty())
			username = "World";
		
		
		out.println("<html><head><title>  yo     </title></head>");
		out.println("<body><h1> Hello " + username + "!!!</h1>");
		out.println("<p>  Nous sommes le " + formattedDate  + "</p>"  );
		out.println("<p>  et il est " + formattedTime +  "...</p> "  );
		out.println("</body>      </html>");
		
	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		  doGet(request, response);
	}
		

}
